﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CCApLMLocationsApp
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CCApLMLocationsApp
{
  public TxObjectList GetLocationsFromSelection()
  {
    TxObjectList locationsFromSelection = new TxObjectList();
    foreach (ITxObject orderedItem in (Collection<ITxObject>) TxApplication.ActiveSelection.GetOrderedItems())
    {
      if (orderedItem is ITxOperation op)
      {
        TxObjectList locationsFromOperation = this.GetLocationsFromOperation(op);
        ((TxObjectList<ITxObject>) locationsFromSelection).Append((TxObjectList<ITxObject>) locationsFromOperation);
      }
    }
    return locationsFromSelection;
  }

  public TxObjectList GetLocationsFromOperation(ITxOperation op)
  {
    TxObjectList locationsFromOperation = new TxObjectList();
    switch (op)
    {
      case ITxOrderedObjectCollection objectCollection:
        int count = ((ITxObjectCollection) objectCollection).Count;
        for (int index = 0; index < count; ++index)
        {
          if (objectCollection.GetChildAt(index) is ITxLocationOperation childAt2)
            ((Collection<ITxObject>) locationsFromOperation).Add((ITxObject) childAt2);
          else if (objectCollection.GetChildAt(index) is ITxOrderedObjectCollection childAt1)
            ((TxObjectList<ITxObject>) locationsFromOperation).Append((TxObjectList<ITxObject>) this.GetLocationsFromOperation(childAt1 as ITxOperation));
        }
        break;
      case ITxLocationOperation locationOperation:
        ((Collection<ITxObject>) locationsFromOperation).Add((ITxObject) locationOperation);
        break;
    }
    return locationsFromOperation;
  }
}
